#ifndef _TEXTURELOADER_H_
#define _TEXTURELOADER_H_

#include <memory>
#include <string>
#include <SERender/Resourses/Texture.h>
#include <SERender/Drive/Drive.h>
#include <array>


namespace SEngine
{
    template<typename T>
    class TextureLoader
    {
    public:
        TextureLoader() {
            this->SetInternalFormat(RGB32F);
            this->SetFormat(RGB);
            this->SetType(FLOAT);
            this->SetParameter(TEXTURE_MAG_FILTER, LINEAR);
            this->SetParameter(TEXTURE_MIN_FILTER, LINEAR);
            this->SetParameter(TEXTURE_WRAP_S, CLAMP_TO_EDGE);
            this->SetParameter(TEXTURE_WRAP_T, CLAMP_TO_EDGE);
        }
        std::unique_ptr<T> CreateTexture(const std::string & fileName);
        std::unique_ptr<T> CreateTexture(const std::array<std::string, 6> & fileName);
        std::unique_ptr<T> CreateTexture(int w = 4, int h = 4, void * buffer = nullptr);
        std::unique_ptr<T> CreateTexture(int w = 4, int h = 4, int d = 4, void * buffer = nullptr);

        void SetLevel(uint32_t lvl) { m_option.level = lvl; }
        void SetInternalFormat(ColorFormat fmt) { m_option.internalFromat = fmt; }
        void SetBorder(uint32_t border) { m_option.border = border; }
        void SetFormat(ColorFormat fmt) { m_option.colorFromat = fmt; }
        void SetType(ElemType type) { m_option.type = type; }
        void SetParameter(TextureParameterKey key, TextureParameterValue value) { 
            if (m_parameters.find(key) != m_parameters.end()) {
                m_parameters.erase(key);
            }
            m_parameters.emplace(key, value); 
        }

    private:
        struct Option {
            uint32_t level{0};
            ColorFormat internalFromat;
            uint32_t border{0};
            ColorFormat colorFromat;
            ElemType type;
        } m_option;
        std::unordered_map<TextureParameterKey, TextureParameterValue> m_parameters;
    };
} // namespace SEngine


#endif